<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="../js/layui/css/layui.css"/>
	</head>
	<body>
		<div class="layui-container">
			<div  class="layui-row">
				
				
				<div class="layui-col-md6 layui-col-lg-offset3" id="search" style="margin-top: 20px;display: none;">
					<fieldset class="layui-elem-field" style="margin-top: 20px;">
					  <legend>加入团队</legend>
					  <div class="layui-form">
					  	<form  action="" method="" class="layui-form ">
								<label class="layui-form-label">团队编码:</label>
									<div class="layui-form" style="margin: 20px;">
										<div class="layui-input-block">
											<input type="text" id="Doc_team_code" name="Doc_team_code" class="layui-input" placeholder="请输入团队唯一编码" autocomplete="off"  />
										</div>
									</div>
					  		<!-- submit -->
					  		<div class="layui-form" style="margin: 20px;">
					  			<div class="layui-input-block">
					  				<input type="submit"  class="layui-btn layui-btn-normal"  lay-submit lay-filter="submit_button" style="width: 100% ;" value="申请加入"/>
					  			</div>
					  		</div>
					  	</form>
					  </div>
					</fieldset>
				</div>
				
				<div class="layui-col-md6 layui-col-lg-offset3" id="my_team_info" style="margin-top: 20px;">
					<fieldset class="layui-elem-field" style="margin-top: 20px;">
					  <legend>我的团队</legend>
					  <div class="layui-form">
					  	<form  action="" method="" class="layui-form ">
					  		<label class="layui-form-label">团队名称:</label>
					  		<div class="layui-form" style="margin: 20px;">
					  			<div class="layui-input-block">
					  				<input type="text" id="team_name" name="team_name" disabled="disabled" class="layui-input" autocomplete="off" />
								</div>
					  		</div>
							
							<label class="layui-form-label">负责人:</label>
							<div class="layui-form" style="margin: 20px;">
								<div class="layui-input-block">
									<input type="text" id="team_leader" name="team_leader" disabled="disabled" class="layui-input" autocomplete="off"  />
								</div>
							</div>
							
							<label class="layui-form-label">团队电话:</label>
							<div class="layui-form" style="margin: 20px;">
								<div class="layui-input-block">
									<input type="text" id="team_phone" name="team_phone" disabled="disabled" class="layui-input" autocomplete="off"  />
								</div>
							</div>
							
							<label class="layui-form-label">团队编码:</label>
							<div class="layui-form" style="margin: 20px;">
								<div class="layui-input-block">
									<input type="text" id="team_code" name="team_code" disabled="disabled" class="layui-input" autocomplete="off"  />
								</div>
							</div>
					  	</form>
					  </div>
					</fieldset>
				</div>
				
				<div class="layui-col-md6 layui-col-lg-offset3">
					<button type="button" id="show" class="layui-btn layui-btn-normal">申请加入团队</button>
				</div>
			</div>
		</div>
	</body>
	
	<script src="../js/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var IsJoinTeam;
		var username = localStorage.getItem("FDSMS");
		window.onload = function(){
			$.ajax({
				url:'http://123.56.67.48:8080/getTeamInfo',
	     	method:'POST',
				contentType:'application/json',
				data:JSON.stringify({
					phone : username//医生的电话
				}),
	      success:function(res){
					console.log(res);
					if(JSON.parse(res).code == 0){
							$("#search").show();
							$("#my_team_info").hide();
							$("#show").hide();
							alert(JSON.parse(res).msg);
					}
					if(JSON.parse(res).code == 1){
						//console.log(res);
						let ll = JSON.parse(res);
						$("#team_name").val(ll.teamName);
						$("#team_leader").val(ll.teamLeaderName);
						$("#team_phone").val(ll.teamPhone);
						$("#team_code").val(ll.teamNum);
					}
				},              
			error:function (res) {
					alert("获取失败"); 
				}					 	                          
			});						
		};
		
		// $("#show").click(function(){
		// 	$("#search").show();
		// 	$("#my_team_info").hide();
		// 	$("#show").hide();
		// });
		
		layui.use(['layer', 'form', 'element'],function(){
				//加载layui表单元素
				var form = layui.form,
					layer = layui.layer,
					element = layui.element; 
				form.render();
				
				form.on("submit(submit_button)", function (data) {
					var k = JSON.stringify({
							doc_team_code : data.field.Doc_team_code,
							identify : 'doctor',
							phone : localStorage.getItem("FDSMS"),
						});
					$.ajax({
						url:'http://123.56.67.48:8080/joinTeam',
						method:'POST',
						contentType:'application/json',
						data:k,
						success:function(res){
							if(JSON.parse(res).code == 0){
								alert(JSON.parse(res).msg);
							}
							else if(JSON.parse(res).code == 1){
								alert(JSON.parse(res).msg);
								window.location.reload();
							}
						},              
						error:function (res) {
							console.log("失败"); 
						}           
					}); 	
				});
			});
	</script>
</html>
